using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class TimerManager : MonoBehaviour
{
    [SerializeField] private float totalTime = 5;
    [SerializeField] private GameObject GameOverPanel;
    [SerializeField] private Text TimerText,HighScoreText,nowScoreText;
    float timer = 0;
    bool isStartTimer = false;

    // Start is called before the first frame update
    void Start()
    {
        isStartTimer = true;
        GameOverPanel.SetActive(false);
        Debug.Log("开始计时");
        TimerText.text = totalTime.ToString();
    }


    // Update is called once per frame
    void Update()
    {
        if (isStartTimer)
        {
            timer += Time.deltaTime;
            Debug.Log("计时中："+(int)timer);
            TimerText.text = (totalTime-(int)timer).ToString();
            if(timer >= totalTime)
            {
                TimerText.text = "时间到!!!";
                Debug.Log("结束计时："+(int)timer);
                isStartTimer = false;
                timer = 0;
                GameOverPanel.SetActive(true);
                ShapesManager.Instance.SetScore();
                nowScoreText.text = PlayerPrefs.GetInt("NowScore").ToString();
                HighScoreText.text = "最高分: " + PlayerPrefs.GetInt("HighScore");
            }
        }
    }
}

